<?php
namespace App\Service\Member;

use Illuminate\Support\Facades\DB;

class ImageService extends BaseService
{
    //图片

//    //列表
//    public function getList($pages)
//    {
//        $start = ($pages['start'] - 1) * $pages['limit'];
//        $db = DB::table($this->dbImg);
//        $total = $db->count();
//        $res = $db->skip($start)->take($pages['limit'])->get();
//        if (!count($res)) {
//            return $this->toback(-2, '没有数据');
//        }
//        $arys = [];
//        foreach ($res as $v) {
//            $v = (array) $v;
//            $arys[] = [
//                'link' => $v['link'],
//                'w' => $v['width'],
//                'h' => $v['height'],
//                'addtime' => $v['addtime'],
//            ];
//        }
//        return $this->toback(0, '', $arys, $total);
//    }

    /**
     * 添加图片
     * @param string $link 图片
     * @param int $w 宽度
     * @param int $h 高度
     */
    public function addImg($link, $w, $h)
    {
        $arys = [
            'type' => 1,
            'link' => $link,
            'width' => $w,
            'height' => $h,
            'addtime' => toDate(),
        ];
        $lastid = $this->dbConn($this->dbImg)->insertGetId($arys);
        if (!$lastid) {
            return $this->toback(-2, 'error');
        }
        return $this->toback();
    }

    /**
     * 添加视频
     * @param string $link
     */
    public function addVideo($link)
    {
        $arys = [
            'type' => 2,
            'link' => $link,
            'addtime' => toDate(),
        ];
        $lastid = $this->dbConn($this->dbImg)->insertGetId($arys);
        if (!$lastid) {
            return $this->toback(-1, 'error');
        }
        return $this->toback();
    }
}